﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.Models.Collection.ProductCollection>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	DetailProduct
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <link rel="stylesheet" type="text/css" href="/Content/smoothness-1.8.13/jquery-ui-1.8.13.custom.css"/>
    <link rel="stylesheet" type="text/css" href="/Content/smoothness-1.8.13/ui.dropdownchecklist.themeroller.css"/>
    <script type="text/javascript" src="/Scripts/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="/Scripts/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript" src="/Scripts/ui.dropdownchecklist-1.4-min.js"></script>
    <script type="text/javascript" src="/Scripts/ui.dropdownchecklist.js"></script>
    <%--Validator--%>
    <script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {

        $("#TypeProductID").dropdownchecklist({icon: {}, width: 350, firstItemChecksAll: true, explicitClose: '...X', forceMultiple: true
            , onComplete: function (selector) {
                var values = "";
                for (i = 0; i < selector.options.length; i++) {
                    if (selector.options[i].selected && (selector.options[i].value != "")) {
                        if (values != "") values += ",";
                        values += selector.options[i].value;
                    }
                }
                
                if (document.all || document.getElementById)
                    document.getElementById('ArrTypeProductID').value = values;
                else
                    document.getElementById('ArrTypeProductID').setAttribute("value", values);

            }
            , onItemClick: function (checkbox, selector) {
                var justChecked = checkbox.prop("checked");
                var checkCount = (justChecked) ? 1 : -1;
                for (i = 0; i < selector.options.length; i++) {
                    if (selector.options[i].selected) checkCount += 1;
                }
            }
         });



        });
    </script>
   

    <!--Editor-->
    <link rel="stylesheet" href="/Editor/themes/default/default.css" />
	<link rel="stylesheet" href="/Editor/plugins/code/prettify.css" />
	<script type="text/javascript" charset="utf-8" src="/Editor/kindeditor.js"></script>
	<script type="text/javascript" charset="utf-8" src="/Editor/lang/en_US.js"></script>
	<script type="text/javascript" charset="utf-8" src="/Editor/plugins/code/prettify.js"></script>
	<script type="text/javascript">
	    KindEditor.ready(function (K) {
	        var editor1 = K.create('#Features', {
	            cssPath: '/Editor/plugins/code/prettify.css',
	            uploadJson: '/Editor/asp.net/upload_json.ashx',
	            fileManagerJson: '/Editor/asp.net/file_manager_json.ashx',
	            allowFileManager: true,
	            afterCreate: function () {
	                var self = this;
	                K.ctrl(document, 13, function () {
	                    self.sync();
	                    K('form[name=example]')[0].submit();
	                });
	                K.ctrl(self.edit.doc, 13, function () {
	                    self.sync();
	                    K('form[name=example]')[0].submit();
	                });
	            }
	        });
	        prettyPrint();
	    });
	</script>
    <!--End Editor-->
    
     <link rel="stylesheet" href="/Content/popup.css" />

    <script type="text/javascript">
        function InsertItems() {
            //string ProductName, string ProductDes, string Features, string Title, string MetaKeyword, 
            //string MetaDescription, int LanguagesID
            var productName = document.getElementById("ProductName_Items").value;
            if (productName == "") {
                return alert('Xin vui lòng nhập tên sản phẩm mục');
            }
            var productDes = document.getElementById("ProductDes_Items").value;
            var features = document.getElementById("Features_Items").value;
            var title = document.getElementById("Title_Items").value;
            var e = document.getElementById("ListLanguagesID");
            var languagesID = e.options[e.selectedIndex].value;
            var metaKeyword = document.getElementById('MetaKeyword_Items').value;
            var metaDescription = document.getElementById('MetaDescription_Items').value;

            var ids = [productName, productDes, features, title, metaKeyword, metaDescription, languagesID];
            $.ajax({
                url: '<%=Url.Action("SaveAddProductItem","Stock")%>',
                data: { ids: ids },
                type: "POST",
                traditional: true,
                success: function (data) {
                    var values = document.getElementById('ArrItemsID').value;
                    if (data != '0') {
                        values += "," + data;
                    }

                    if (document.all || document.getElementById) {
                        document.getElementById('ArrItemsID').value = values;
                    }
                    else {
                        document.getElementById('ArrItemsID').setAttribute("value", values);
                    }
                }
            });
            alert("lưu thành công!");
            document.getElementById("mysubmit").innerHTML = '<input type="submit" value="Save" class="button themed"/>';
            document.getElementById("ProductName_Items").value = "";
            document.getElementById("ProductDes_Items").value = "";
            document.getElementById("Features_Items").value = "";
            document.getElementById("Title_Items").value = "";
            var ec = document.getElementById("ListLanguagesID");
            document.getElementById('MetaKeyword_Items').value = "";
            document.getElementById('MetaDescription_Items').value = "";
        }
    </script>
        <script type="text/javascript">
            function check() {
                var arrayid = document.getElementById("ArrItemsID").value;
                if (arrayid == "") {
                    alert("Bạn chưa dịch ngôn ngữ!");

                }
            }
    </script>
    <script type="text/javascript">
        function UpdateItems() {
            //string ProductName, string ProductDes, string Features, string Title, string MetaKeyword, 
            //string MetaDescription,int ProductID, int LanguagesID,int ProductItemID
            var productName = document.getElementById("ProductName_Items").value;
            if (productName == "") {
                return alert('Xin vui lòng nhập tên sản phẩm');
            }
            var productDes = document.getElementById("ProductDes_Items").value;
            var features = document.getElementById("Features_Items").value;
            var title = document.getElementById("Title_Items").value;
            var e = document.getElementById("ListLanguagesID");
            var languagesID = e.options[e.selectedIndex].value;
            var metaKeyword = document.getElementById('MetaKeyword_Items').value;
            var metaDescription = document.getElementById('MetaDescription_Items').value;
            var productID = document.getElementById('ProductID').value;
            var productItemID = document.getElementById('ProductItemID').value;
            var ids = [productName, productDes, features, title, metaKeyword, metaDescription, productID, languagesID, productItemID];
            $.ajax({
                url: '<%=Url.Action("UpdateProductItem","Stock")%>',
                data: { ids: ids },
                type: "POST",
                traditional: true,
                success: function (data) {
                    var result = document.getElementById('Result').value;
                    document.getElementById('Result').value = data;
                }
            });
            alert("lưu thành công!");
            document.getElementById("mysubmit").innerHTML = '<input type="submit" value="Save" class="button themed"/>';
            document.getElementById("ProductName_Items").value = "";
            document.getElementById("ProductDes_Items").value = "";
            document.getElementById("Features_Items").value = "";
            document.getElementById("Title_Items").value = "";
            var ec = document.getElementById("ListLanguagesID");
            document.getElementById('MetaKeyword_Items').value = "";
            document.getElementById('MetaDescription_Items').value = "";
        }


        function GetItems(dropDownList) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var values = document.getElementById('ProductID').value;
            var ids = [selectedReport.value, values];
            $.ajax({              
                url: '<%=Url.Action("GetProductItemByLanguageIDandProductID","Stock")%>',            
                data: { ids: ids },
                type: "POST",
                traditional: true,
                success: function (data) {
                    $('#ProductName_Items').val(data.split("|")[1]);
                    $('#ProductDes_Items').val(data.split("|")[2]);
                    $('#Features_Items').val(data.split("|")[3]);
                    $('#Title_Items').val(data.split("|")[4]);
                    $('#MetaKeyword_Items').val(data.split("|")[5]);
                    $('#MetaDescription_Items').val(data.split("|")[6]);
                    $('#ProductItemID').val(data.split("|")[0]);

                }
            });
        }
    </script>

          <!--Popup-->
     
     <script type="text/javascript">
         $(document).ready(function () {

             //When you click on a link with class of poplight and the href starts with a #  
             $('a.poplight[href^=#]').click(function () {
                 var popID = $(this).attr('rel'); //Get Popup Name 
                 var popURL = $(this).attr('href'); //Get Popup href to define size 

                 //Pull Query & Variables from href URL 
                 var query = popURL.split('?');
                 var dim = query[1].split('&');
                 var popWidth = dim[0].split('=')[1]; //Gets the first query string value 

                 //Fade in the Popup and add close button 
                 $('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend('<a href="#" class="close"><img src="/Content/images/popup-closeButton.png" class="btn_close" title="Close Window" alt="Close" /></a>');
                 document.getElementById("viewbutton").innerHTML = '<a href="#" class="close"><div class="button themed" style="float:left;width: 61px;">Đóng lại</div></a>';
                 //Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css 
                 var popMargTop = ($('#' + popID).height() + 80) / 2;
                 var popMargLeft = ($('#' + popID).width() + 80) / 2;

                 //Apply Margin to Popup 
                 $('#' + popID).css({
                     'margin-top': -popMargTop,
                     'margin-left': -popMargLeft
                 });

                 //Fade in Background 
                 $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag. 
                 $('#facebox_overlay').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer  

                 return false;
             });


             //Close Popups and Fade Layer 
             $('a.close, #facebox_overlay').live('click', function () { //When clicking on the close or fade layer... 
                 $('#facebox_overlay , .popup_block').fadeOut(function () {
                     $('#facebox_overlay, a.close').remove();
                 }); //fade them both out 

                 return false;
             });


         }); 
    </script> 
   <% Html.EnableClientValidation(); %>
   <% using (Html.BeginForm((bool)ViewData["IsAdd"] ? "SaveAddProduct" : "SaveEditProduct", "Stock", FormMethod.Post, new { siteGuid = "sendFileForm", language = "sendFileForm", id = "sendFileForm", enctype = "multipart/form-data" }))
            {%>     
     <div class="clear"></div>
       
        <div class="box ">
		    <h2 class="box-header"><%=(bool)ViewData["IsAdd"] ? "Sản phẩm mới" : "Sửa thông tin sản phẩm" %></h2>
		    <div class="box-content">

                <label class="form-label"> Tên sản phẩm </label>
                <%= Html.TextBoxFor(m => m.ProductName, new { @class = "form-field small" })%> <span style="color:Red;font-weight:bold"><%= Html.ValidationMessageFor(m => m.ProductName) %></span>
                <%
                SelectList data = (SelectList)ViewData["ListLanguage"];
                if (data.ToList().Count > 1)
                   { %>
                <a href="#?w=600" rel="popup_name" class="poplight"  style="float:right;clear:right;"><div class="button themed">Dịch sản phẩm</div></a> 
                <%} %>
                <label class="form-label"> Mã sản phẩm </label>
                <%= Html.TextBoxFor(m => m.ProductCode, new { @class = "form-field small" })%>
                
                 <label class="form-label"> Mô tả </label>
                 <%= Html.TextAreaFor(m => m.ProductDes, new { @class = "form-field half" })%>
                                   
                 <label class="form-label"> Ảnh </label>
                 
                  <%if (Model.Images != null)
                   {
                       string src = Model.Images;
                       
                           %>
                            
                               <img src="http://image.atf.com.vn/<%=Model.Images %>" width="130px" alt="" id="imgname" onclick="window.open('/Editor/aspnet/Images.aspx','images',' width=750,height=450,left=150,top=200,toolbar=no,status=0,scrollbars=1,location=0,');" />  
                           <%
                   }
                   else
                   { 
                   %>
                    <img src="/Content/images/noimage.gif" width="130px" id="imgname" alt="" onclick="window.open('/Editor/aspnet/Images.aspx','images',' width=750,height=450,left=150,top=200,toolbar=no,status=0,scrollbars=1,location=0,');" />
                    <%   
                   }
                  %> 
                  <%--<input type="hidden" id="url" name="url"/>--%>
                  <%=Html.HiddenFor(m=>m.Images) %>

                              
                    
                  <label class="form-label"> Type Product </label>
                  <%= Html.DropDownList("TypeProductID", (MultiSelectList)ViewData["ListTypeProductDrop"], "Select all", new { @multiple = "multiple" })%>
                 
                 <label class="form-label"> Active </label>
                 <%if (Model.Status == 1)
                   {
                   %>
                        <%=Html.CheckBoxFor(m=>m.Active,true) %>
                   <%
                     }
                   else
                   {
                       if ((bool)ViewData["IsAdd"])
                       {
                       %>
                        <%=Html.CheckBoxFor(m=>m.Active,true) %>
                       <%
                       }
                       else
                       { 
                       %>
                        <%=Html.CheckBoxFor(m=>m.Active) %>
                       <%
                       }
                    
                   } 
                    %>
                 <label class="form-label"> Features </label>
                 <%= Html.TextAreaFor(m => m.Features, new { @class = "form-field full" })%>
                 
                 <label class="form-label">Metadata Title </label>
                 <%= Html.TextBoxFor(m => m.Title, new { @class = "form-field small" })%>

                 <label class="form-label">Metadata Keyword </label>
                 <%= Html.TextBoxFor(m => m.MetaKeyword, new { @class = "form-field half" })%>

                 <label class="form-label">Metadata Description </label>
                 <%= Html.TextAreaFor(m => m.MetaDescription, new { @class = "form-field small" })%> 

                 <%=Html.TextBoxFor(m => m.TypeProductID, new {@Style="display:none" })%>

                 <%=Html.TextBoxFor(m=>m.ArrTypeProductID,new {@Style="display:none"}) %>
                 
                 <%=Html.HiddenFor(m=>m.ProductID) %>
                 <p>
                <%=ViewData["Result"]%>
                </p>
                   <div id="mysubmit" name="mysubmit" style="float:left;">
                <%                
                if (data.ToList().Count > 1)
                { %>

                 <% if ((bool)ViewData["IsAdd"])
                    {%>
                 
                 <div id="divsubmit" name="divsubmit" class="button themed" onclick="check()"> Lưu lại</div>
                 <%}
                    else
                    {%>
                    <input type="submit" value="Lưu lại" class="button themed"/>
                 <%}
                }
                else
                { %>
                   <input type="submit" value="Lưu lại" class="button themed"/>
                <%} %>
                 </div>                
              <%-- <input type="submit" value="Lưu lại" class="button themed"/>--%>
                
	        </div>
	    </div>
        <div class="clear"></div>
        <div id="popup_name" class="popup_block" >                                
                    <div id="TemplateTable" style=" width:auto; float:left;" > </div>
                    <div id="ItemPage" class="box-content" style="height:500px; overflow:scroll;">
                           <div class="clear"></div>
                            
		                        
                                        
                                        <label class="form-label"> Chọn ngôn ngữ  </label>
                                        <% bool tran = true;
                                           if ((bool)ViewData["IsAdd"])
                                           { 
                                               %>
                                                    <%= Html.DropDownList("ListLanguagesID", (SelectList)ViewData["ListLanguage"], "--Chọn ngôn ngữ--", new { @class = "width20",@Style="width: 160px;"})%>  
                                               <% 
                                           }
                                           else
                                           {               
                                                %>
                                                    <%= Html.DropDownList("ListLanguagesID", (SelectList)ViewData["ListLanguage"], "--Chọn ngôn ngữ--", new { @class = "width20", onchange = "GetItems(this);", @Style="width:160px;" })%>  
                                                <%
                                           }
                                         %>

                                        

                                        <label class="form-label"> Tên sản phẩm </label>
                                        <input type="text" id="ProductName_Items" class="form-field half" />

                                        <label class="form-label"> Mô tả </label>
                                        <input type="text" id="ProductDes_Items" class="form-field half" style="width:508px;height:60px;" />

                                        <label class="form-label"> Thông số kỹ thuật </label>
                                        <input type="text" id="Features_Items" class="form-field half" style="width:508px;height:60px;" />

                                        <label class="form-label">Metadata Title </label>
                                        <input type="text" id="Title_Items" class = "form-field small" style="width:508px;"/>

                                        <label class="form-label">Metadata Keyword </label>
                                        <input type="text" id="MetaKeyword_Items" class="form-field half" style="width:508px;" />

                                        <label class="form-label">Metadata Description </label>
                                        <input type="text" id="MetaDescription_Items" class="form-field half" style="width:508px;" />

                                        <div style="padding:10px;">
                                        <div style="float:left; margin-right:5px;">
                                    
	                                    <% 
                                           if ((bool)ViewData["IsAdd"])
                                           { 
                                               %>
                                                    <a href="#"  onclick="InsertItems()" ><div class="button themed">Lưu</div></a> 
                                                                                                        
                                               <% 
                                            }
                                           else
                                           { 
                                                %>
                                                           
                                                    <a href="#"  onclick="UpdateItems()" ><div class="button themed">Lưu</div></a> 
                                                      
                                                <%
                                           }
                                         %>
                                       </div>
                                       <div id="viewbutton" style="float:left;">
	                                    <a href="#" class="close"> <div class="button themed" style="float:left;width:61px;">Đóng lại</div> </a>
                                       </div>
                                    </div>
                                        
                            <div class="clear"></div>     
                    </div>                                                        
                </div>  
    <%=Html.Hidden("ArrItemsID")%> 
    <%=Html.Hidden("ProductItemID")%>  
    <%=Html.Hidden("Result") %>  
    <% } %>
    <script type="text/javascript">
        var selecteds = document.getElementById("ArrTypeProductID").value;
        var combox = document.getElementById("TypeProductID");
        var arrSeleteds = selecteds.split(",");
        for (i = 0; i < combox.options.length; i++) {
            for (j = 0; j < arrSeleteds.length; j++) {
                if (combox.options[i].value == arrSeleteds[j]) {
                    combox.options[i].selected=true;
                }
            }
        }

    </script>
</asp:Content>
